/*
    设置条目展示隐藏
 */
import { ActionType } from "../../index";
import { fromJS } from "immutable";
import { v4 as uuidv4 } from "uuid";

const config = {
  instances: {
    default: {
      data: undefined,
      title: undefined,
      componentId: undefined,
    },
  },
};
const initState = fromJS(config);

const reducer = (state = initState, action: any) => {
  let newState = state;
  switch (action.type) {
    case ActionType.STORE_SHOP_INIT:
      newState = state.withMutations((item: any) => {
        item.setIn(["instances", action.componentId, "data"], action.data);
        item.setIn(["instances", action.componentId, "layout"], action.layout);
        item.setIn(["instances", action.componentId, "shopCard"], action.shopCard);
      });
      return newState;
    case ActionType.STORE_SHOP_CARD_CHECK:
      newState = state.withMutations((item: any) => {
        item.setIn(["instances", action.componentId, "shopCard"], action.shopCard);
      });
      return newState;
  }
  return state;
};

export default reducer;
